package com.kuang.controller;

import com.kuang.pojo.AstControllerHeart;
import com.kuang.pojo.AstManageDeviceRegister;
import com.kuang.service.asset.AstControllerHeartService;
import com.kuang.service.asset.AstManageDeviceRegisterService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstManageDeviceRegisterController {

    @Resource
    AstManageDeviceRegisterService astManageDeviceRegisterService;

    /**
     * 获取全部数据
     * @param model
     * @return
     */
    @RequestMapping("getAstManageDeviceRegisters")
    public String getAstManageDeviceRegisters(Model model){
        List<AstManageDeviceRegister> astManageDeviceRegisters = astManageDeviceRegisterService.selectAll();
        model.addAttribute("datas",astManageDeviceRegisters);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "mqtt/ast_manage_device_register_list";
    }

    /**
     * 获取数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstManageDeviceRegistersByExample")
    public String getAstManageDeviceRegistersByExample(AstManageDeviceRegister astManageDeviceRegister,Model model){

        List<AstManageDeviceRegister> astManageDeviceRegisters = astManageDeviceRegisterService.selectAllByExample(astManageDeviceRegister);
        model.addAttribute("datas",astManageDeviceRegisters);
        model.addAttribute("device_code",astManageDeviceRegister.getDevice_code());
        model.addAttribute("ver",astManageDeviceRegister.getVer());
        return "mqtt/ast_manage_device_register_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstManageDeviceRegisterById/{id}")
    public String getAstManageDeviceRegisterById(@PathVariable("id") String id, Model model){
        AstManageDeviceRegister astManageDeviceRegister = new AstManageDeviceRegister();
        astManageDeviceRegister.setAst_manage_device_register_id(id);
        List<AstManageDeviceRegister> astManageDeviceRegisters = astManageDeviceRegisterService.selectAllByExample(astManageDeviceRegister);
        model.addAttribute("data",astManageDeviceRegisters.get(0));
        return "mqtt/ast_manage_device_register_from";
    }

}
